package com.javabasic.serialize.model;

import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author mir.xiong
 * @version 0.0.1
 * @description
 * @see
 * @since Created by work on 2021/11/28 4:16 下午
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class WebSite {
    private String url;
    private String name;
    private WebSiteEnum webSiteEnum;
    private Content content;

    private UrlType urlType;

    /**
     * 添加通过外部属性，来动态序列化设置值的方式
     * @param content
     */
    @JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXTERNAL_PROPERTY, property = "webSiteEnum")
    @JsonSubTypes(value =
            {
                    @JsonSubTypes.Type(value = BlogContent.class, name = "BLOG"),
                    @JsonSubTypes.Type(value = VideoContent.class, name = "VIDEO"),
                    @JsonSubTypes.Type(value = ForumContent.class, name = "FORUM"),
            })
    public void setContent(Content content) {
        this.content = content;
    }
}
